package com.abel.bigwater.kmgw

import org.mybatis.spring.annotation.MapperScan
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.CommandLineRunner
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.context.annotation.ComponentScan

@SpringBootApplication
@ComponentScan(basePackages = ["com.abel.bigwater"])
@MapperScan(basePackages = ["com.abel.bigwater.mapper"])
class BwKmingGwApplication : CommandLineRunner {
    @Autowired
    var ewideServer: EwideServer? = null

    @Autowired
    var kmingServer: KmingServer? = null

    @Autowired
    var qdiesServer: QdiesServer? = null

    @Autowired
    var kmingClient: KmingVirtualDeviceBean? = null

    @Autowired
    var iwgServer: IwgServer? = null

    /**
     * start service-list.
     */
    override fun run(vararg args: String?) {
        ewideServer!!.startService()

        // start kming-server
        kmingServer!!.startService()

        // qdies
        qdiesServer!!.startService()

        // start client
//        kmingClient!!.startService()

        // iwg-server
        iwgServer!!.startService()
    }
}

fun main(args: Array<String>) {
    try {
        runApplication<BwKmingGwApplication>(*args)
    } catch (ex: Exception) {
        lgr.error("启动大表网关失败: ${ex.message}", ex)
    }
}

private val lgr = LoggerFactory.getLogger(BwKmingGwApplication::class.java)
